﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TwitterNameTableAdapters;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            int intuserid;
            const int ANONIMUSER = -1; const int ALLUSER = 0;
            MessagesTableAdapter MessageAdapter = new MessagesTableAdapter();
            UsersTableAdapter UserAdapter = new UsersTableAdapter();

            string userid1 = HttpContext.Current.User.Identity.Name.ToString();

            try
            {
                if (userid1 == "")
                {
                    GridView1.DataSource = MessageAdapter.GetDataBy_id_for_user(ANONIMUSER);
                }
                else
                {
                    intuserid = (int) UserAdapter.ScalarQuery_getUserID(userid1);
                    GridView1.DataSource = MessageAdapter.GetDataBy_id_for_user(ALLUSER);
                    // GridView1.DataSource = MessageAdapter.GetData();
                }
                
                GridView1.BackColor = System.Drawing.Color.DodgerBlue;
                GridView1.ForeColor = System.Drawing.Color.Snow;
                GridView1.CellPadding = 0;
                GridView1.CellSpacing = 1;
                GridView1.BorderColor = System.Drawing.Color.SkyBlue;
                GridView1.BorderWidth = 1;
                GridView1.ShowHeader = GridView1.ShowHeader ? false : true;
                GridView1.DataBind();
                Response.Write("Значение параметра id = " + Request.QueryString["id"]);
            }
            catch (Exception ee) {
                Response.Write(ee.Message);
             //string msg = "";
             //   for (int i = 0; i < e.Errors.Count; i++)
             //   {
             //       msg += "Error #" + i + " Message: " + e.Errors[i].Message + "\n";
             //   }
             //   System.Console.WriteLine(msg);
                ;
            }
        }  

        
    }
}
